package com.youchuang.action.main;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.youchuang.action.BaseAction;
import com.youchuang.bean.Category;
import com.youchuang.common.Constant;
import com.youchuang.service.MainService;

import net.sf.json.JSONArray;

/**
 * 主页左栏目录
 * 
 * @author Administrator
 *
 */
@Namespace("/main")
@ParentPackage("shopping-default")
public class CategoryAction extends BaseAction {
	private Logger logger = Logger.getLogger(CategoryAction.class.getSimpleName());
	private List<Category> cats;

	@Resource
	private MainService mainService;

	@Actions({
			@Action(value = "categoryAction", results = {
					@Result(name = Constant.CATEGORY, location = "/WEB-INF/jsp/main/cateleft.jsp") }),
			@Action(value = "toBookInsert", results = {
					@Result(name = Constant.CATEGORY, location = "/WEB-INF/jsp/ad/bookinsert.jsp") }) })
	public String execute() throws Exception {
		logger.info("excetion is execute");
		cats = mainService.findCategoryByAll();
		logger.info("response json cats =" + JSONArray.fromObject(cats).toString());
		return Constant.CATEGORY;
	}

	public List<Category> getCats() {
		return cats;
	}

	public void setCats(List<Category> cats) {
		this.cats = cats;
	}

}
